﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RoundButton
{
    public partial class RoundButton : Control
    {
        //public RoundButton()
        //{
        //    InitializeComponent();
        //}
        private Color backgroundColor = Color.LightBlue;
        private Color borderColor = Color.Gray;

        public Color BorderColor
        {
            get { return borderColor; }
            set { borderColor = value; Invalidate(); }
        }
        private string text = "roundButton1";

        public override string Text
        {
            get
            {
                return text;
            }
            set
            {
                text = value;
                Invalidate();
            }
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            Graphics graphics = pe.Graphics;
            int penWidth = 4;
            Pen pen = new Pen(borderColor,penWidth);
            int fontHeight = 10;
            Font font = new Font("Arial",fontHeight);
            SolidBrush brush = new SolidBrush(backgroundColor);
            graphics.FillRectangle(brush,0,0,Width,Height);
            SolidBrush textBrush = new SolidBrush(Color.Black);
            graphics.DrawRectangle(pen,(int)penWidth/2,(int)penWidth/2,Width - penWidth,Height-penWidth);
            SizeF textSize = graphics.MeasureString(text,font);
            graphics.DrawString(text,font,textBrush,(Width - textSize.Width) / 2, (Height - textSize.Height) / 2);

        }
    }
}
